home *** CD-ROM | disk | FTP | other *** search
- Path: hubcap.clemson.edu!hubcap!mjs
- From: mjs@hubcap.clemson.edu (M. J. Saltzman)
- Newsgroups: comp.lang.c
- Subject: Re: How to detect if a number has fractions
- Date: 8 Apr 96 15:00:11 GMT
- Organization: Clemson University
- Message-ID: <mjs.828975611@hubcap>
- References: <4kb1p8$gph@gate.compart.fi>
- NNTP-Posting-Host: hubcap.clemson.edu
- X-Newsreader: NN version 6.5.0 #1
-
- joonas.kervinen@pcb.compart.fi (joonas kervinen) writes:
-
- >Here's a small detail (not quite Win spesific, sorry!) that's bugging
-
- Of course, in comp.lang.c, we prefer non-Win-specific questions.
-
- >me: How do I detect in Borland C (BCC4.5 or 5.0) whether a double
- >value has fractions. And I mean quickly, not using time consuming
- >floating point functions.
-
- In ANSI/ISO C, you can call the modf() function, which will work
- reliably for any double value. If you don't like that, you can simply
- compare the value cast to an integer type with the original value,
- but then you need to worry about whether the cast value fits in
- the integer type:
-
- /* This works only if LONG_MIN <= x && x <= LONG_MAX */
-
- double x;
-
- if ( (long) x == x )
- puts("x is integral");
- else
- puts("x is not integral");
-
- It's not necessarily clear which will be faster on a particular
- system--changes in representation can be as slow as floating-point
- manipulations.
-
- I don't know if BCC offers any other specialized facilities for
- accomplishing this task, but I doubt it. Besides, why use
- non-portable methods to accomplish tasks that can be accomplished
- portably (unless the performance penalty is huge)?
-
- >Please answer via e-mail.
-
- If you can't be bothered to scan for responses to your own message, you
- deserve not to see them. If you think the request will generate more
- traffic than it's worth, at least offer to summarize.
- --
- Matthew Saltzman
- Clemson University Math Sciences
- mjs@clemson.edu
-